import { getStore } from '../../utils/storageUtils';
import { STORE_KEY } from '../../constant';
import { REMOVE_USER, SET_USER } from '../constant';

const initValue = getStore(STORE_KEY) || {};

export default function user (prev = initValue, action) {
  const {
    type,
    data
  } = action;
  switch (type) {
  case SET_USER:
    return data;
  case REMOVE_USER:
    return {};
  default:
    return prev;
  }
}
